$(document).ready(function () {

    var Modal = $(".modal-msg");
    if(Modal.contents.length == 2) {
        Modal.fadeOut();
    }

    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $('.login-form').submit(function(event){
        event.preventDefault();
        var accountName = $('.account').val();
        var accessKey = $('.access-key').val();
        $.ajax({
           method:'POST',
            url: url+'/login',
            data: $('.login-form').serialize(),
            success: function(response){
                var res = JSON.parse(response);
                if (res.statusCode == 200) {
                    Modal.addClass("msg-success")
                    Modal.removeClass("msg-error")
                    Modal.addClass("text-success")
                    Modal.html("Logged In. Redirecting...").slideDown(500);
                    Modal.delay(3000);
                    window.location.href = url+"/dashboard";
                    Modal.slideUp(500);
                } else if (res.statusCode == 400) {
                    Modal.addClass("msg-error")
                    Modal.addClass("text-danger")
                    Modal.html("Unable to Login. Please check credentials and Internet Connectivity.").slideDown(500);
                    Modal.delay(4000);
                    Modal.slideUp(500);
                }
            },
        });
    });
});